Skip to content

Conversation

sebthom
Copy link
Contributor

@sebthom sebthom commented Aug 10, 2025

To avoid errors like:

Error: MCP tool "find_code" response (194537 tokens) exceeds maximum
allowed tokens (25000). Please use pagination, filtering, or limit
parameters to reduce the response size.

The first commit b28e40d addresses the problem.

The second commits 805bd67 adds tests and a CI workflow for the mcp tools.

To avoid errors like:
Error: MCP tool "find_code" response (194537 tokens) exceeds maximum
allowed tokens (25000). Please use pagination, filtering, or limit
parameters to reduce the response size.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds maxResults parameter and text output format support to prevent token limit errors that could occur when using the MCP server. The changes introduce pagination capabilities and a more token-efficient text format alongside the existing JSON format.

Key changes:

  • Added max_results parameter to find_code and find_code_by_rule functions
  • Added output_format parameter with "text" as default (more token-efficient) and "json" options
  • Added comprehensive unit and integration tests with CI workflow

Reviewed Changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
main.py Added pagination parameters and text output format to core search functions
tests/test_main.py Comprehensive unit tests for all MCP server functions with mocking
tests/test_integration.py Integration tests using actual fixture files
tests/fixtures/example.py Test fixture with Python code examples
pyproject.toml Added development dependencies and testing configuration
.github/workflows/test.yml CI workflow for cross-platform testing
README.md Updated documentation for new parameters

Copy link
Member

@HerringtonDarkholme HerringtonDarkholme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update.

Some comments are left.

main.py Outdated
output = '\n'.join(non_empty_lines)
header = f"Found {len(non_empty_lines)} matches (limited to {max_results}):\n"
else:
header = f"Found {len(non_empty_lines)} matches:\n"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly, the header can be omitted.

main.py Outdated
# Limit the results
non_empty_lines = non_empty_lines[:max_results]
output = '\n'.join(non_empty_lines)
header = f"Found {len(non_empty_lines)} matches (limited to {max_results}):\n"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a single line of "Showing the {max_len} lines of results"

@sebthom sebthom force-pushed the maxResults branch 2 times, most recently from bbe75e6 to 34b4335 Compare August 14, 2025 22:54
@HerringtonDarkholme HerringtonDarkholme merged commit 6659a60 into ast-grep:main Aug 15, 2025
@sebthom sebthom deleted the maxResults branch August 15, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants